home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util4 / 0utils.lha / 0Utils / GetWord.data < prev    next >
Text File  |  1995-08-19  |  2KB  |  89 lines

  1.  
  2. #ifdef TPLTER
  3.  
  4. GetWord = {
  5.  
  6.     SHORT = {{ get one in a list of words }};
  7.  
  8.     DESCRIPTION = {{
  9.     get a number and a couple of strings and
  10.     find the n-th string starting with 1.
  11.  
  12.     Negative numbers cause counting with the
  13.     last word.
  14.  
  15.     The resulting string is sent to STDOUT.
  16.  
  17.     Numbers, that exceed the number of words,
  18.     result in a returncode "10" (so does number=0)
  19.  
  20.      RESULT
  21.     word [number-1]
  22.     }};
  23.  
  24.     BUGS = {{
  25.     there are problems, if GetWord is invoked with
  26.     wrong word number in Scripts: for unknown reason
  27.     the secondary result is cleared early.
  28.     (see .KnownBugs)
  29.  
  30.     The documentation wrongly stated a returncode 9
  31.     on wrong numbers.
  32.     }};
  33.  
  34.  
  35.     EXAMPLES = {{
  36.     >GetWord  1 ali baba
  37.     "ali"
  38.  
  39.     >GetWord -1 ali baba
  40.     "baba"
  41.  
  42.     >GetWord 3 ali baba
  43.     "GetWord: bad number"
  44.     }};
  45.  
  46.     HISTORY = {{
  47.     01-08-93 b_noll created
  48.     23-08-93 b_noll completed
  49.     11-02-95 b_noll slight changes
  50.     20-02-95 b_noll restructured source
  51.     21-02-95 b_noll added version/format-prefix/offset
  52.     20-03-95 b_noll added args diagnostics
  53.     19-08-95 b_noll created .data file
  54.     }};
  55.  
  56.  
  57.     Template = "NUMBER/N/A,WORDS/M";
  58.     Arguments = {{
  59.     LONG  * num;
  60.     STRPTR* words;
  61.     }};
  62.  
  63.     version = "1.3";
  64.     body = {{
  65.         long num, cnt;
  66.  
  67.         for (cnt = 0; argv->words[cnt]; ++cnt);
  68.  
  69.         num  = *(argv->num);
  70.         if (num < 0) num += cnt+1;
  71.  
  72.         //retval = RETURN_WARN; /* if no error is wanted ... */
  73.  
  74.         if (num == 0 || num > cnt) {
  75.         SetIoErr (ERROR_BAD_NUMBER);
  76.         } else {
  77.         retval = RETURN_WARN;
  78.         if (PutStr (argv->words[num-1]) == 0) retval = RETURN_OK;
  79.         PutStr("\n");
  80.         } /* if */
  81.  
  82.  
  83.     }};
  84.  
  85. };
  86.  
  87. #endif
  88.  
  89.